package com.yafengliang.swagger.controller;

import com.yafengliang.swagger.model.User;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * @author liangyafeng
 * @Description:
 * @date 2020/4/20 11:50
 */
@Api
@RestController
@RequestMapping(value = "/user")
@Slf4j
public class UserController {

    @ApiOperation(value = "新增用户", notes = "新增注册")
    @RequestMapping(value = "addUser", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity addUser(@RequestBody User user) {
        log.info("addUser::{}", user.toString());
        return new ResponseEntity(null, HttpStatus.OK);
    }

    @ApiOperation(value = "修改用户" ,  notes="修改用户")
    @RequestMapping(value="/updateUser",method= RequestMethod.POST,consumes= MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity updateUser(@RequestBody User user){
        log.info("updateUser:::"+user.toString());
        return new ResponseEntity(null, HttpStatus.OK );
    }

    @ApiOperation(value = "删除用户" ,  notes="删除用户")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户标识", required = true, paramType = "query", dataType = "String")
    })
    @RequestMapping(value="/deleteUser",method= RequestMethod.DELETE)
    public ResponseEntity deleteUser(@RequestParam("userId") String userId){
        log.info("deleteUser:::"+userId);
        return new ResponseEntity(null, HttpStatus.OK);
    }

    @ApiOperation(value = "查询用户" ,  notes="查询用户")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户标识", required = true, paramType = "query", dataType = "String")
    })
    @RequestMapping(value="/queryUser",method= RequestMethod.GET)
    public ResponseEntity queryUser(@RequestParam("userId") String userId){
        log.info("queryUser:::"+userId);
        User user = new User(userId,"zhansgan","123456");
        return new ResponseEntity(null, HttpStatus.OK);
    }
}
